home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 34.zip / BS1 part 34 / Weubblers handler.adf / examples / mscopy.c < prev    next >
C/C++ Source or Header  |  1989-01-10  |  3KB  |  118 lines

  1. #define MAXCOMP 7
  2. #define MINTRACKLEN 6200
  3. /* Will assume that every Track has *at least* MINTRACKLEN words!!*/
  4. #define MINAMIGALEN 6300
  5. /* Will assume that all AMIGAs are able to hold MINAMIGALEN words per track */
  6. #define MAXAMIGALEN 6380
  7. /* Will assume that no AMIGA is able to hold more than MAXAMIGALEN words */
  8. #define TRASH 0
  9. /* Will assume that the last read TRASH bytes are actually trash.
  10.    Can be 20 for MSDos, Should be 0 (or better negative) for AMIGA disks.
  11.    Be Aware: The new Disk must have AT LEAST a capacity of (old capacity-TRASH).*/
  12.  
  13. int Drive=0;
  14. main(argc,argv)
  15. int argc;
  16. char **argv;
  17. {
  18. unsigned short *TrackBuffer;
  19. char c;
  20. int track,head;
  21. int count;
  22. register int i,j;
  23. int fromdrive=0;
  24. int todrive=1;
  25. int first=0,second=0;
  26. int max=0,min=100000;
  27. int emptysym=StandardMfmEnc(0); /* Fill the empty spaces with 0s! */
  28. unsigned short *ptr;
  29. int found,attempt,tries;
  30.  
  31. InitMotor();
  32. TrackBuffer=(unsigned short *)AllocChipMem(2*(TrackLen+2000))+2000;
  33. for (i=-2000;i<0;i++) TrackBuffer[i]=emptysym;
  34.  
  35. OnceAgain:
  36.  
  37. printf("\n\nThis Prog will copy a disk from Drive 0 to Drive 1.\n");
  38. printf("If you are sure that this is what you want to do, please type 'y'\n");
  39. printf("after inserting source- and destination-disks in the respective drives.\n");
  40. printf("To quit, type anything else.\n");
  41.  
  42. do
  43. c=getchar();
  44. while (c=='\n');
  45.  
  46. if (toupper(c)!='Y') {printf("Poooh... Finishing.\n");_abort();}
  47.  
  48. max=0;
  49. min=10000;
  50. for (track=0;track<84;track++)
  51. for (head=0;head<2;head++)
  52.  {
  53.     attempt=0;
  54.     NextAttempt:
  55.     tries=0;
  56.     NextTry:
  57.     ReadTrack(TrackBuffer,fromdrive,track,head);
  58.     first=0;
  59.     second=0;
  60.     found=0;
  61.     TrackBuffer[-1]=emptysym;
  62.     TrackBuffer[-2]=emptysym;
  63.     TrackBuffer[-3]=emptysym;
  64.     for (i=0;i<MAXAMIGALEN;i++)
  65.      if (TrackBuffer[i]==0x4489)
  66.      {
  67.       while (TrackBuffer[i]==SYNC) i++;
  68.       TrackBuffer[i-1]=SYNC;
  69.       TrackBuffer[i-2]=SYNC;
  70.       TrackBuffer[i-3]=SYNC;
  71.  
  72.       /* Now test if a DataSector has been read in first: */
  73.       if (first)
  74.        if (second==0)
  75.         {second=-1;
  76.          if ((tries<3)&&(i-first>150))
  77.           goto NextTry;}
  78.  
  79.       if (first==0) first=i;
  80.       if (i>MINTRACKLEN)
  81.       {
  82.       for (j=0;j<MAXCOMP;j++)
  83.        if (TrackBuffer[i+j]!=TrackBuffer[first+j]) goto none;
  84.       if (i>max) max=i;
  85.       if (i<min) min=i;
  86.       found=-1;
  87.       goto done;
  88.       }
  89.      none:;
  90.      }
  91.     done:
  92.     if (found==0)
  93.         {
  94.         tries++;
  95.         if (tries!=4) goto NextTry;
  96.         if (attempt==4)
  97.          aprintf(stderr,"Giving up this Track.\n");
  98.         else
  99.          {attempt++;
  100.           aprintf(stderr,"Read Error on Track %ld Head %ld!\n",track,head);
  101.           goto NextAttempt;}
  102.         }
  103.     else
  104.         {
  105.          i=i-3;
  106.          if (i>MINAMIGALEN) i-=TRASH;
  107.          /* Make sure that the first Bytes are actually written out,
  108.             hoping that the last TRASH Bytes are trash.This is *surely*
  109.             wrong for AMIGA-disks.*/
  110.          ptr=TrackBuffer+i-TrackLen;
  111.          WriteTrack(ptr,todrive,track,head);
  112.         }
  113.  }
  114. printf("Statistics:    Shortest Track: %ld  Longest Track: %ld\n",min,max);
  115. printf("Copy finished.\n");
  116. goto OnceAgain;
  117. }
  118.